
var data = [];

$(function() {	
	Tip.emp('负责人');
	
	$("input[id^='customer_s']:visible").autocomplete(Test.customer);
		
	$("select[id^='way_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
});

var Export = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},			
			
			"添加": function() {				
				if (!confirm("确认是否添加？")) {
					return false;
				}				
	
				var form = $("#form_add")[0];
	
				var body = { };
				
				body.emp = form.emp.value;
				body.tec = form.tec.value;
				body.date = form.date.value;
				
				body.customer = form.customer.value;
				body.customer_x = Common.customer_x(form);
								
				body.amount = form.amount.value;
				body.currency = form.currency.value;				
				body.rate = form.rate.value;
				body.rmb = form.rmb.value;
				
				body.name = form.name.value;
				body.way = form.way.value;
				body.number = form.number.value;
				
				body.weight1 = form.weight1.value;
				body.weight2 = form.weight2.value;
				body.content = form.content.value;				
				
				// body.item = data;
				body.item = $.toJSON(data);
				
				$(this).dialog("close");
	
				$.post('express.php?do=Export.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'express.php?do=Export.edit&id=' + id;
		var c2 = 'express.php?do=Export.view&id=' + id;
		var c3 = 'express.php?do=Export.copy&id=' + id;
				
		var a1 = ['编辑信息', 'url', 'Export.dialog_edit_', '780x450'];	
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '700x450'];
		var a3 = ['复制信息', 'url', 'Export.dialog_copy_', '700x450'];
		
		var s = c1 + ", " + c2 + ", " + c3;

		return this.popup_(e, [a1, a2, a3], s);
	},

	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var ss = 'express.php?do=Export.ss&id=' + id;
		var bb = ['修改状态', 'url', 'Export.dialog_ss', '400x200', '修改状态'];
		
		s += ", " + ss;
		a.push(bb);
		
		return popup(e, a, s);
	},

	/**
	 * 修改状态
	 */
	dialog_ss: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('express.php?do=Export.ajax_emp', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'express.php?do=Export.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
				
				var body = { };
				body.id = form.id.value;
				
				body.emp = form.emp.value;
				body.tec = form.tec.value;
				body.date = form.date.value;
				
				body.customer = form.customer.value;
				body.customer_x = Common.customer_x(form);
								
				body.amount = form.amount.value;
				body.currency = form.currency.value;				
				body.rate = form.rate.value;
				body.rmb = form.rmb.value;
				
				body.name = form.name.value;
				body.way = form.way.value;
				body.number = form.number.value;
				
				body.weight1 = form.weight1.value;
				body.weight2 = form.weight2.value;
				body.content = form.content.value;
				
				// body.item = data;
				body.item = $.toJSON(data);
				
				$(this).dialog("close");
	
				var url = 'express.php?do=Export.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
				
				var body = { };
				
				body.emp = form.emp.value;
				body.tec = form.tec.value;
				body.date = form.date.value;
				
				body.customer = form.customer.value;
				body.customer_x = Common.customer_x(form);
								
				body.amount = form.amount.value;
				body.currency = form.currency.value;				
				body.rate = form.rate.value;
				body.rmb = form.rmb.value;
				
				body.name = form.name.value;
				body.way = form.way.value;
				body.number = form.number.value;
				
				body.weight1 = form.weight1.value;
				body.weight2 = form.weight2.value;
				body.content = form.content.value;	
				
				// body.item = data;
				body.item = $.toJSON(data);
				
				$(this).dialog("close");
	
				var url = 'express.php?do=Export.addPost';
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
		
	list_start: function (url, view) {
		$.getJSON('finance.php?do=In.ajax_emp', function(json) {
			if (json.status == 1) {
				if (confirm("是否要开始收款？")) {
					list(url, view);
				}
			} else {
				_error();
			}
		});
	},
	
	list_finish: function (url, view) {
		$.getJSON('finance.php?do=In.ajax_emp', function(json) {
			if (json.status == 1) {
				if (confirm("是否要完成收款？")) {
					list(url, view);
				}
			} else {
				_error();
			}
		});
	},
	
	popup_all: function (e, p2) {
		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'express.php?do=Export.delete' + p2;
		var c2 = 'express.php?do=Export.xls' + p2;
			
		var a1 = ['删除信息', 'url', 'Common.list_delete'];
		var a2 = ['导出Excel', 'url', 'jswin', '1024x768'];
		
		var s = c1 + ", " + c2;

		return popup(e, [a1, a2], s);
	}
};
